
//  ZZLC
//
//  Created by 杨春至 on 2017/12/15.
//  Copyright © 2017年 ZhongZeng. All rights reserved.
//

#import "TiXianiVC.h"
#import "InputSecretVC.h"
#import "ChongzhiOrTiXianHistoryVC.h"
#import "BankModel.h"
#import "CountModel.h"
@interface TiXianiVC ()
@property(nonatomic)InputSecretVC *inputSecretVc;
@property(nonatomic)CountModel *countModel;
@end

@implementation TiXianiVC
//todo 安卓可以提现不能充值
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = self.titleStr;
    [self loadNet];
    [self initUI];
    // Do any additional setup after loading the view from its nib.
}
- (void)initUI
{
    __weak typeof (self) weakSelf = self;
    self.view.backgroundColor = COLORE_GLOBLE_BACKGOUNDCOLOR;
    if ([self.title isEqualToString:@"充值"]) {
        UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithTitle:@"充值记录"  style:UIBarButtonItemStyleDone target:self action:@selector(rightVCShow:)];
         rightItem.tag = 102;//充值的tag
        self.navigationItem.rightBarButtonItem = rightItem;
        self.chongzhiIndicatorView.hidden = false;
        self.chongzhiOrTiXianLabel.text = @"充值金额";
        self.inputMoneyTF.placeholder = @"请输入充值金额";
        [self.stateBtn setTitle:@"确认充值" forState:UIControlStateNormal];

    }
    else
    {
        UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithTitle:@"提现记录"  style:UIBarButtonItemStyleDone target:self action:@selector(rightVCShow:)];
        rightItem.tag = 101;//提现的tag
        self.navigationItem.rightBarButtonItem = rightItem;
        
        self.chongzhiIndicatorView.hidden = false;
        self.chongzhiOrTiXianLabel.text = @"提现金额";
        self.inputMoneyTF.placeholder = @"请输入提现金额";
        [self.stateBtn setTitle:@"确认提现" forState:UIControlStateNormal];
    }
    [self.stateBtn bk_whenTapped:^{
        if ([self.title isEqualToString:@"提现"]) {
            [weakSelf popupInputSecret];
        }
        if ([self.title isEqualToString:@"充值"]) {
            [weakSelf chongzhisubmitNetWorking];
        }
    }];
    self.bankIconImageV.image = Image([BankModel bankURI]);
    self.bankCategoryLabel.text = [BankModel bankName];
    NSArray *indicatorArray = nil;
    indicatorArray= [[BankModel txRule]componentsSeparatedByString:@"。"];
    NSLog(@"indicatorArray%@",indicatorArray);
    if (indicatorArray.count == 5) {
        self.firstIndicatorLabel.text = indicatorArray[0];
        self.secondIndicatorLabel.text = indicatorArray[1];
        self.thirdIndicatorLabel.text = indicatorArray[2];
        self.fourthIndicatorLabel.text = indicatorArray[3];
        
    }
    self.bankNumLabel.text = [NSString stringWithFormat:@"尾号:%@",[BankModel cardLast]];

}
- (void)loadNet
{
    NSDictionary *param = @{@"authorization":[UserModel authorization]};
    [NetWorkingManager postWithRequestUrl:@"User/showMyAccount" AndParameters:@{@"parameters":[param DataTOjsonStringAndAddVersion]} AndRequestBlock:^(NSDictionary *responseObject) {
        NSLog(@"%@",responseObject);
        self.countModel  = [CountModel objectWithKeyValues:[responseObject objectForKey:@"obj"]];
        self.accountAvailableMoneyLabel.text = [NSString stringWithFormat:@"%.2f",[_countModel.leftMoney doubleValue]/100];
   
    } FailBlock:^(NSDictionary *errDic) {
        
    }];
}
- (void)chongzhisubmitNetWorking{
    [NetWorkingManager postWithRequestUrl:self.urlStr AndParameters:@{@"parameters":[@{@"username":[UserModel userName]?[UserModel userName]:@"",@"txn_amt":self.inputMoneyTF.text,@"authorization":[UserModel authorization]} DataTOjsonStringAndAddVersion]} AndRequestBlock:^(NSDictionary *responseObject) {
        
    } FailBlock:^(NSDictionary *errDic) {
        
    }];
}
- (void)tixiansubmitNetWorkingStr:(NSString *)str{
    NSDictionary *params = @{@"username":[UserModel userName]?[UserModel userName]:@"",@"trans_money":self.inputMoneyTF.text,@"payPassword":str,@"type":@"2",@"authorization":[UserModel authorization]};
    
    [NetWorkingManager postWithRequestUrl:self.urlStr AndParameters:@{@"parameters":[params DataTOjsonStringAndAddVersion]} AndRequestBlock:^(NSDictionary *responseObject) {
       
    } FailBlock:^(NSDictionary *errDic) {
        
    }];
}
- (void)rightVCShow:(UIBarButtonItem *)sender
{
    ChongzhiOrTiXianHistoryVC *vc = [[ChongzhiOrTiXianHistoryVC alloc]initWithNibName:@"ChongzhiOrTiXianHistoryVC" bundle:nil];
    switch (sender.tag) {
        case 101:
            vc.titleStr = @"提现";
            vc.urlStr = @"User/findTxRecord";
            break;
            
        default:
            vc.titleStr = @"充值";
            vc.urlStr = @"User/findCzRecord";
            break;
    }
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)popupInputSecret{
    __weak typeof (self) weakSelf = self;
    dispatch_async(dispatch_get_main_queue(), ^{
        [weakSelf.view addSubview:self.inputSecretVc.view];
    });
}


-(InputSecretVC *)inputSecretVc{
    __weak typeof (self) weakSelf = self;
    if (_inputSecretVc) {
        return _inputSecretVc;
    }
    _inputSecretVc = [[InputSecretVC alloc] init];
    _inputSecretVc.view.frame = (CGRect){0,0,K_SCREEN_WIDTH,K_SCREEN_HEIGHT};
    _inputSecretVc.block = ^(NSString *secret){
        [weakSelf tixiansubmitNetWorkingStr:secret];
    };
    return _inputSecretVc;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
